<script setup lang="ts">
import { showSuccessToast } from 'vant';
import { Ref, ref } from 'vue'
import { API } from '../api';
import { XYCUpdateDataDto } from '../api/_Api';
import { UnwrapRef } from 'vue';
const loading = ref(false)
const onSubmit = async (values: UnwrapRef<typeof form>) => {
    console.log('submit', values);
    try {
        loading.value = true
        const { data: { data } } = await API.userControllerXycManagerDataAdd(values)
        console.log("🚀 ~ onSubmit ~ data:", data)
        showSuccessToast({ message: '保存成功~' });
    } finally {
        loading.value = false
    }
};
const form: Ref<XYCUpdateDataDto> = ref({ share: '', buy: '', browse: '' } as unknown as XYCUpdateDataDto)
API.userControllerXycDataGet().then(({ data: { data: t = {} } }) => {
    form.value.share = t.share || 0
    form.value.buy = t.buy || 0
    form.value.browse = t.browse || 0
})
</script>

<template>
    <van-form @submit="onSubmit" class="form">
        <van-cell-group inset>
            <van-field v-model.number="form.share" name="share" type="digit" label="分享数" placeholder="分享数"
                :rules="[{ required: true, message: '请填写分享数' }]" />
            <van-field v-model.number="form.buy" name="buy" type="digit" label="售卡数" placeholder="售卡数"
                :rules="[{ required: true, message: '请填写售卡数' }]" />
            <van-field v-model.number="form.browse" name="browse" type="digit" label="浏览数" placeholder="浏览数"
                :rules="[{ required: true, message: '请填写浏览数' }]" />
        </van-cell-group>
        <div style="margin: 16px;">
            <van-button round block type="primary" native-type="submit" :loading="loading">
                提交
            </van-button>
        </div>
    </van-form>
</template>

<style scoped lang="less">
.form {
    padding: 30px 0;
    min-height: 100vh;
    width: 100%;
}
</style>
